package com.alix.paymoney.http;

import java.nio.charset.Charset;
import java.security.MessageDigest;

/**
 * Created by mars on 2016/10/10.
 * 邮箱：l.mars@foxmail.com
 * 说明：
 */

public class DigestUtils {

    /***
     * MD5加码 生成32位md5码
     */
    public static String md5Hex(String str) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] md5Bytes = md5.digest(str.getBytes(Charset.forName("UTF-8")));
            return Hex.encodeHexString(md5Bytes);
        } catch (Exception e) {
            return null;
        }
    }

    public static String md5Hex(byte[] bytes) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] md5Bytes = md5.digest(bytes);
            return Hex.encodeHexString(md5Bytes);
        } catch (Exception e) {
            return null;
        }
    }
}
